package dao

import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import javax.inject.Inject
import scala.concurrent.{ExecutionContext, Future}

class BlockDao  @Inject()(protected val dbConfigProvider: DatabaseConfigProvider)
                         (implicit exec: ExecutionContext) extends
  HasDatabaseConfigProvider[JdbcProfile]{

  import profile.api._

  def insert(row:Seq[BlockRow]) : Future[Unit] = {
    db.run(Block ++= row).map(_=>())
  }

  def getByGeneId(geneid:String) : Future[Option[String]] ={
    db.run(Block.filter(_.geneid === geneid).map(_.block).result.headOption)
  }

  def getAll :Future[Seq[BlockRow]] = {
    db.run(Block.result)
  }

  def getByIds(id:Seq[Int]) : Future[Seq[BlockRow]] = {
    db.run(Block.filter(_.id.inSetBind(id)).result)
  }

  def getById(id:Int) : Future[Seq[BlockRow]] ={
    db.run(Block.filter(_.id === id).result)
  }

}
